﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMIS_ERP.Web.Order_Info
{
    public partial class Search_Manager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UCode"].ToString().Substring(2, 1) == "0")
                {
                    Response.Write("<script>alert('没有权限！');location.href='../ERP_Manager/EM_Page_Main.aspx';</script>");
                }
                Bind_SID();
            }
        }

        /// <summary>绑定加盟店ID
        ///     <remarks>2010-12-10 河大信管团队</remarks>
        /// </summary>
        private void Bind_SID()
        {
            string siProvince = "", siCity = "";
            if (Session["UType1"].ToString() == "0")
            {
                siProvince="%%";
                siCity = "%%";
            }
            else if (Session["UType1"].ToString() == "1")
            {
                siProvince = Session["UProvince"].ToString();
                siCity = "%%";
            }
            else if (Session["UType1"].ToString() == "2")
            {
                siProvince = Session["UProvince"].ToString();
                siCity = Session["UCity"].ToString();
            }
            IMIS_ERP.BLL.Shop_Info bll = new BLL.Shop_Info();
            SqlDataReader dr = bll.GetsiID_M(siProvince, siCity);
            ddlSID.DataSource = dr;
            ddlSID.DataTextField = "siID";
            ddlSID.DataBind();
            dr.Close();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string time1 = "2010-1-1", time2 = "2110-1-1";
            if (txthTime1.Text != "")
            {
                time1 = txthTime1.Text.Trim() + " 00:00:00";
            }
            if (txthTime2.Text != "")
            {
                time2 = txthTime2.Text.Trim() + " 23:59:59";
            }
            IMIS_ERP.BLL.Order_Products bll = new IMIS_ERP.BLL.Order_Products();
            SqlDataReader dr = bll.GetSiSum(ddlSID.SelectedValue, ddloiStatus.SelectedValue, time1, time2);
            DataTable dt = new DataTable();
            dt.Columns.Add("opPcID");
            dt.Columns.Add("opNumSum");
            dt.Columns.Add("opAreaSum");
            dt.Columns.Add("opWeightSum");
            dt.Columns.Add("opFee1Sum");
            dt.Columns.Add("opFee2Sum");
            decimal sum0 = 0,sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    dt.Rows.Add(dr["opPcID"], dr["opNumSum"], dr["opAreaSum"], dr["opWeightSum"], dr["opFee1Sum"], dr["opFee2Sum"]);
                    sum0 += Convert.ToDecimal(dr["opNumSum"]);
                    sum1 += Convert.ToDecimal(dr["opAreaSum"]);
                    sum2 += Convert.ToDecimal(dr["opWeightSum"]);
                    sum3 += Convert.ToDecimal(dr["opFee1Sum"]);
                    sum4 += Convert.ToDecimal(dr["opFee2Sum"]);
                }
            }
            dt.Rows.Add("总计",sum0, sum1, sum2, sum3, sum4);
            GV.DataSource = dt;
            GV.DataBind();
            dr.Close();
        }

        /// <summary>响应GridView事件：创建数据行时
        /// 	<remark>2010-12-08 BY 河北大学信管团队</remark>
        /// </summary>
        protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //为数据行增加鼠标移动到行特性
                e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;this.style.backgroundColor='" + IMIS_ERP.BLL.Assistant.getColor1 + "'");
                //为数据行增加鼠标离开行特性
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }
}